// pages/MusicIndex/MusicDetailIndex/MusicDetailIndex.js
const MusicHttp = require("../../../utils/MusicHttp")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        arrList: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: async function (options) {
        var urlArr = [":3000/top/playlist/highquality", ":3000/album/newest", ":3000/personalized/djprogram"];
        var { url } = options;
        var httpRes = await MusicHttp.getHttp(url);
        if (url == urlArr[0]) {
            httpRes.data.playlists.forEach(item => {
                item.picUrl = item.coverImgUrl
            })
            // console.log(httpRes);
            this.setData({
                arrList: httpRes.data.playlists
            })
        } else if (url == urlArr[1]) {
            httpRes.data.albums.forEach(item => {
                item.playCount = item.id;
            })
            this.setData({
                arrList: httpRes.data.albums
            })
        } else if (url == urlArr[2]) {
            httpRes.data.result.forEach(item => {
                item.playCount = item.program.adjustedPlayCount;
            })
            this.setData({
                arrList: httpRes.data.result
            })
        }
    },

    jumpDetail(e){
        var {aid} = e.currentTarget.dataset;
        wx.navigateTo({
          url: `/pages/MusicIndex/musicDetails/musicDetails?id=${aid}`,
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})